
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>网关-Gateway · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-back-to-top-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchors/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-sidebar-style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-pageview-count/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="13.配置中心-Config.html" />
    
    
    <link rel="prev" href="11.熔断器-Hystrix.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    前言
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">基础篇</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="../java基础/IO流基础.html">
            
                <a href="../java基础/IO流基础.html">
            
                    
                    IO流基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="../java基础/集合.html">
            
                <a href="../java基础/集合.html">
            
                    
                    集合
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="../java基础/异常处理.html">
            
                <a href="../java基础/异常处理.html">
            
                    
                    异常处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="../java基础/线程.html">
            
                <a href="../java基础/线程.html">
            
                    
                    线程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="../java基础/网络编程.html">
            
                <a href="../java基础/网络编程.html">
            
                    
                    网络编程
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">进阶篇</li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="../java进阶/MySQL.html">
            
                <a href="../java进阶/MySQL.html">
            
                    
                    MySQL
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="../java进阶/Oracle.html">
            
                <a href="../java进阶/Oracle.html">
            
                    
                    Oracle
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="../java进阶/Redis.html">
            
                <a href="../java进阶/Redis.html">
            
                    
                    Redis
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="../java进阶/Netty.html">
            
                <a href="../java进阶/Netty.html">
            
                    
                    Netty
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="../java进阶/Spring.html">
            
                <a href="../java进阶/Spring.html">
            
                    
                    Spring
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="../java进阶/SpringMVC.html">
            
                <a href="../java进阶/SpringMVC.html">
            
                    
                    SpringMVC
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.7" data-path="../java进阶/单元测试.html">
            
                <a href="../java进阶/单元测试.html">
            
                    
                    SpringBoot单元测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.8" data-path="../java进阶/设计模式.html">
            
                <a href="../java进阶/设计模式.html">
            
                    
                    二十三个设计模式
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.8.1" data-path="../java进阶/工厂模式.html">
            
                <a href="../java进阶/工厂模式.html">
            
                    
                    工厂模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.8.2" data-path="../java进阶/单例模式.html">
            
                <a href="../java进阶/单例模式.html">
            
                    
                    单例模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.8.3" data-path="../java进阶/建造者模式.html">
            
                <a href="../java进阶/建造者模式.html">
            
                    
                    建造者模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.8.4" data-path="../java进阶/原型模式.html">
            
                <a href="../java进阶/原型模式.html">
            
                    
                    原型模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.8.5" data-path="../java进阶/适配器模式.html">
            
                <a href="../java进阶/适配器模式.html">
            
                    
                    适配器模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.8.6" data-path="../java进阶/责任链模式.html">
            
                <a href="../java进阶/责任链模式.html">
            
                    
                    责任链模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.8.7" data-path="../java进阶/桥接模式.html">
            
                <a href="../java进阶/桥接模式.html">
            
                    
                    桥接模式
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">高级篇</li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="1.cloud架构选型.html">
            
                <a href="1.cloud架构选型.html">
            
                    
                    Spring Cloud
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1.1" data-path="2.Provider-支付模块.html">
            
                <a href="2.Provider-支付模块.html">
            
                    
                    Provider-支付模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.2" data-path="3.Consumer-订单模块.html">
            
                <a href="3.Consumer-订单模块.html">
            
                    
                    Consumer-订单模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.3" data-path="4.重构-Common模块.html">
            
                <a href="4.重构-Common模块.html">
            
                    
                    重构-Common模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.4" data-path="5.注册中心-Enreka.html">
            
                <a href="5.注册中心-Enreka.html">
            
                    
                    注册中心-Enreka
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.5" data-path="6.负载均衡-@LoadBalance.html">
            
                <a href="6.负载均衡-@LoadBalance.html">
            
                    
                    负载均衡-@LoadBalance
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.6" data-path="7.更换注册中心-Zookeeper.html">
            
                <a href="7.更换注册中心-Zookeeper.html">
            
                    
                    更换注册中心-Zookeeper
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.7" data-path="8.更换注册中心-Consul.html">
            
                <a href="8.更换注册中心-Consul.html">
            
                    
                    更换注册中心-Consul
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.8" data-path="9.负载均衡-Ribbon.html">
            
                <a href="9.负载均衡-Ribbon.html">
            
                    
                    负载均衡-Ribbon
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.9" data-path="10.服务调用-OpenFeign.html">
            
                <a href="10.服务调用-OpenFeign.html">
            
                    
                    服务调用-OpenFeign
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.10" data-path="11.熔断器-Hystrix.html">
            
                <a href="11.熔断器-Hystrix.html">
            
                    
                    熔断器-Hystrix
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="4.1.11" data-path="12.网关-Gateway.html">
            
                <a href="12.网关-Gateway.html">
            
                    
                    网关-Gateway
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.12" data-path="13.配置中心-Config.html">
            
                <a href="13.配置中心-Config.html">
            
                    
                    配置中心-Config
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.13" data-path="14.消息总线-bus.html">
            
                <a href="14.消息总线-bus.html">
            
                    
                    消息总线-Bus
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.14" data-path="15.消息驱动-stream.html">
            
                <a href="15.消息驱动-stream.html">
            
                    
                    消息驱动-Stream
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.15" data-path="16.链路监控-Sleuth.html">
            
                <a href="16.链路监控-Sleuth.html">
            
                    
                    链路监控-Sleuth
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.16" data-path="17.注册中心&配置中心-nacos.html">
            
                <a href="17.注册中心&配置中心-nacos.html">
            
                    
                    注册中心&配置中心-nacos
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.17" data-path="18.限流-sentinel.html">
            
                <a href="18.限流-sentinel.html">
            
                    
                    限流-sentinel
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="../java高级/JUC.html">
            
                <a href="../java高级/JUC.html">
            
                    
                    神秘的JUC包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="../java高级/Docker.html">
            
                <a href="../java高级/Docker.html">
            
                    
                    Docker
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="../java高级/布隆过滤器.html">
            
                <a href="../java高级/布隆过滤器.html">
            
                    
                    布隆过滤器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="../java高级/Redission.html">
            
                <a href="../java高级/Redission.html">
            
                    
                    Redission
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.6" data-path="../java高级/MQ.html">
            
                <a href="../java高级/MQ.html">
            
                    
                    消息队列
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.7" data-path="../java高级/JVM.html">
            
                <a href="../java高级/JVM.html">
            
                    
                    JVM
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.8" data-path="../java书籍/《Effective Java》读书笔记.html">
            
                <a href="../java书籍/《Effective Java》读书笔记.html">
            
                    
                    《Effective Java》读书笔记 
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.8.1" data-path="../java书籍/创建和销毁对象.html">
            
                <a href="../java书籍/创建和销毁对象.html">
            
                    
                    创建和销毁对象
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">番外篇</li>
        
        
    
        <li class="chapter " data-level="5.1" data-path="../java面试/面试题.html">
            
                <a href="../java面试/面试题.html">
            
                    
                    面试题
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="../番外篇/小程序.html">
            
                <a href="../番外篇/小程序.html">
            
                    
                    微信小程序
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >网关-Gateway</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h3 id="1-springcloud-&#x5DE5;&#x4F5C;&#x6D41;&#x7A0B;"><a name="1-springcloud-&#x5DE5;&#x4F5C;&#x6D41;&#x7A0B;" class="plugin-anchor" href="#1-springcloud-&#x5DE5;&#x4F5C;&#x6D41;&#x7A0B;"><i class="fa fa-link" aria-hidden="true"></i></a>1. springcloud &#x5DE5;&#x4F5C;&#x6D41;&#x7A0B;</h3>
<p><img src="https://tva1.sinaimg.cn/large/e6c9d24ely1h3vsz015nwj20g40fu74y.jpg" alt="&#x8DEF;&#x7531;&#x8BF7;&#x6C42;&#x56FE;"></p>
<p>Spring Cloud Gateway &#x5DE5;&#x4F5C;&#x6D41;&#x7A0B;&#x8BF4;&#x660E;&#x5982;&#x4E0B;&#xFF1A;</p>
<ol>
<li>&#x5BA2;&#x6237;&#x7AEF;&#x5C06;&#x8BF7;&#x6C42;&#x53D1;&#x9001;&#x5230; Spring Cloud Gateway &#x4E0A;&#x3002;</li>
<li>Spring Cloud Gateway &#x901A;&#x8FC7; Gateway Handler Mapping &#x627E;&#x5230;&#x4E0E;&#x8BF7;&#x6C42;&#x76F8;&#x5339;&#x914D;&#x7684;&#x8DEF;&#x7531;&#xFF0C;&#x5C06;&#x5176;&#x53D1;&#x9001;&#x7ED9; Gateway Web Handler&#x3002;</li>
<li>Gateway Web Handler &#x901A;&#x8FC7;&#x6307;&#x5B9A;&#x7684;&#x8FC7;&#x6EE4;&#x5668;&#x94FE;&#xFF08;Filter Chain&#xFF09;&#xFF0C;&#x5C06;&#x8BF7;&#x6C42;&#x8F6C;&#x53D1;&#x5230;&#x5B9E;&#x9645;&#x7684;&#x670D;&#x52A1;&#x8282;&#x70B9;&#x4E2D;&#xFF0C;&#x6267;&#x884C;&#x4E1A;&#x52A1;&#x903B;&#x8F91;&#x8FD4;&#x56DE;&#x54CD;&#x5E94;&#x7ED3;&#x679C;&#x3002;</li>
<li>&#x8FC7;&#x6EE4;&#x5668;&#x4E4B;&#x95F4;&#x7528;&#x865A;&#x7EBF;&#x5206;&#x5F00;&#x662F;&#x56E0;&#x4E3A;&#x8FC7;&#x6EE4;&#x5668;&#x53EF;&#x80FD;&#x4F1A;&#x5728;&#x8F6C;&#x53D1;&#x8BF7;&#x6C42;&#x4E4B;&#x524D;&#xFF08;pre&#xFF09;&#x6216;&#x4E4B;&#x540E;&#xFF08;post&#xFF09;&#x6267;&#x884C;&#x4E1A;&#x52A1;&#x903B;&#x8F91;&#x3002;</li>
<li>&#x8FC7;&#x6EE4;&#x5668;&#xFF08;Filter&#xFF09;&#x53EF;&#x4EE5;&#x5728;&#x8BF7;&#x6C42;&#x88AB;&#x8F6C;&#x53D1;&#x5230;&#x670D;&#x52A1;&#x7AEF;&#x524D;&#xFF0C;&#x5BF9;&#x8BF7;&#x6C42;&#x8FDB;&#x884C;&#x62E6;&#x622A;&#x548C;&#x4FEE;&#x6539;&#xFF0C;&#x4F8B;&#x5982;&#x53C2;&#x6570;&#x6821;&#x9A8C;&#x3001;&#x6743;&#x9650;&#x6821;&#x9A8C;&#x3001;&#x6D41;&#x91CF;&#x76D1;&#x63A7;&#x3001;&#x65E5;&#x5FD7;&#x8F93;&#x51FA;&#x4EE5;&#x53CA;&#x534F;&#x8BAE;&#x8F6C;&#x6362;&#x7B49;&#x3002;</li>
<li>&#x8FC7;&#x6EE4;&#x5668;&#x53EF;&#x4EE5;&#x5728;&#x54CD;&#x5E94;&#x8FD4;&#x56DE;&#x5BA2;&#x6237;&#x7AEF;&#x4E4B;&#x524D;&#xFF0C;&#x5BF9;&#x54CD;&#x5E94;&#x8FDB;&#x884C;&#x62E6;&#x622A;&#x548C;&#x518D;&#x5904;&#x7406;&#xFF0C;&#x4F8B;&#x5982;&#x4FEE;&#x6539;&#x54CD;&#x5E94;&#x5185;&#x5BB9;&#x6216;&#x54CD;&#x5E94;&#x5934;&#x3001;&#x65E5;&#x5FD7;&#x8F93;&#x51FA;&#x3001;&#x6D41;&#x91CF;&#x76D1;&#x63A7;&#x7B49;&#x3002;</li>
<li>&#x54CD;&#x5E94;&#x539F;&#x8DEF;&#x8FD4;&#x56DE;&#x7ED9;&#x5BA2;&#x6237;&#x7AEF;&#x3002;</li>
</ol>
<p>&#x603B;&#x800C;&#x8A00;&#x4E4B;&#xFF0C;&#x5BA2;&#x6237;&#x7AEF;&#x53D1;&#x9001;&#x5230; Spring Cloud Gateway &#x7684;&#x8BF7;&#x6C42;&#x9700;&#x8981;&#x901A;&#x8FC7;&#x4E00;&#x5B9A;&#x7684;&#x5339;&#x914D;&#x6761;&#x4EF6;&#xFF0C;&#x624D;&#x80FD;&#x5B9A;&#x4F4D;&#x5230;&#x771F;&#x6B63;&#x7684;&#x670D;&#x52A1;&#x8282;&#x70B9;&#x3002;&#x5728;&#x5C06;&#x8BF7;&#x6C42;&#x8F6C;&#x53D1;&#x5230;&#x670D;&#x52A1;&#x8FDB;&#x884C;&#x5904;&#x7406;&#x7684;&#x8FC7;&#x7A0B;&#x524D;&#x540E;&#xFF08;pre &#x548C; post&#xFF09;&#xFF0C;&#x6211;&#x4EEC;&#x8FD8;&#x53EF;&#x4EE5;&#x5BF9;&#x8BF7;&#x6C42;&#x548C;&#x54CD;&#x5E94;&#x8FDB;&#x884C;&#x4E00;&#x4E9B;&#x7CBE;&#x7EC6;&#x5316;&#x63A7;&#x5236;&#x3002;</p>
<p>Predicate &#x5C31;&#x662F;&#x8DEF;&#x7531;&#x7684;&#x5339;&#x914D;&#x6761;&#x4EF6;&#xFF0C;&#x800C; Filter &#x5C31;&#x662F;&#x5BF9;&#x8BF7;&#x6C42;&#x548C;&#x54CD;&#x5E94;&#x8FDB;&#x884C;&#x7CBE;&#x7EC6;&#x5316;&#x63A7;&#x5236;&#x7684;&#x5DE5;&#x5177;&#x3002;&#x6709;&#x4E86;&#x8FD9;&#x4E24;&#x4E2A;&#x5143;&#x7D20;&#xFF0C;&#x518D;&#x52A0;&#x4E0A;&#x76EE;&#x6807; URI&#xFF0C;&#x5C31;&#x53EF;&#x4EE5;&#x5B9E;&#x73B0;&#x4E00;&#x4E2A;&#x5177;&#x4F53;&#x7684;&#x8DEF;&#x7531;&#x4E86;&#x3002;</p>
<h3 id="2-&#x4E09;&#x5927;&#x6838;&#x5FC3;&#x7EC4;&#x4EF6;"><a name="2-&#x4E09;&#x5927;&#x6838;&#x5FC3;&#x7EC4;&#x4EF6;" class="plugin-anchor" href="#2-&#x4E09;&#x5927;&#x6838;&#x5FC3;&#x7EC4;&#x4EF6;"><i class="fa fa-link" aria-hidden="true"></i></a>2. &#x4E09;&#x5927;&#x6838;&#x5FC3;&#x7EC4;&#x4EF6;</h3>
<ul>
<li><strong>&#x8DEF;&#x7531;&#xFF1A;</strong>&#x7F51;&#x5173;&#x6700;&#x57FA;&#x672C;&#x7684;&#x6A21;&#x5757;&#x3002;&#x5B83;&#x7531;&#x4E00;&#x4E2A; ID&#x3001;&#x4E00;&#x4E2A;&#x76EE;&#x6807; URI&#x3001;&#x4E00;&#x7EC4;&#x65AD;&#x8A00;&#xFF08;Predicate&#xFF09;&#x548C;&#x4E00;&#x7EC4;&#x8FC7;&#x6EE4;&#x5668;&#xFF08;Filter&#xFF09;&#x7EC4;&#x6210;&#x3002;</li>
<li><strong>&#x65AD;&#x8A00;&#xFF1A;</strong>&#x8DEF;&#x7531;&#x8F6C;&#x53D1;&#x7684;&#x5224;&#x65AD;&#x6761;&#x4EF6;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x901A;&#x8FC7; Predicate &#x5BF9; HTTP &#x8BF7;&#x6C42;&#x8FDB;&#x884C;&#x5339;&#x914D;&#xFF0C;&#x4F8B;&#x5982;&#x8BF7;&#x6C42;&#x65B9;&#x5F0F;&#x3001;&#x8BF7;&#x6C42;&#x8DEF;&#x5F84;&#x3001;&#x8BF7;&#x6C42;&#x5934;&#x3001;&#x53C2;&#x6570;&#x7B49;&#xFF0C;&#x5982;&#x679C;&#x8BF7;&#x6C42;&#x4E0E;&#x65AD;&#x8A00;&#x5339;&#x914D;&#x6210;&#x529F;&#xFF0C;&#x5219;&#x5C06;&#x8BF7;&#x6C42;&#x8F6C;&#x53D1;&#x5230;&#x76F8;&#x5E94;&#x7684;&#x670D;&#x52A1;&#x3002;</li>
<li><strong>&#x8FC7;&#x6EE4;&#x5668;&#xFF1A;</strong>&#x8FC7;&#x6EE4;&#x5668;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x5B83;&#x5BF9;&#x8BF7;&#x6C42;&#x8FDB;&#x884C;&#x62E6;&#x622A;&#x548C;&#x4FEE;&#x6539;&#xFF0C;&#x8FD8;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x5B83;&#x5BF9;&#x4E0A;&#x6587;&#x7684;&#x54CD;&#x5E94;&#x8FDB;&#x884C;&#x518D;&#x5904;&#x7406;&#x3002;</li>
</ul>
<p><img src="https://tva1.sinaimg.cn/large/e6c9d24ely1h3w4g4q8dpj21i80nwq6n.jpg" alt=""></p>
<h3 id="3&#x4E24;&#x79CD;&#x8DEF;&#x7531;&#x914D;&#x7F6E;&#x65B9;&#x5F0F;"><a name="3&#x4E24;&#x79CD;&#x8DEF;&#x7531;&#x914D;&#x7F6E;&#x65B9;&#x5F0F;" class="plugin-anchor" href="#3&#x4E24;&#x79CD;&#x8DEF;&#x7531;&#x914D;&#x7F6E;&#x65B9;&#x5F0F;"><i class="fa fa-link" aria-hidden="true"></i></a>3.&#x4E24;&#x79CD;&#x8DEF;&#x7531;&#x914D;&#x7F6E;&#x65B9;&#x5F0F;</h3>
<ul>
<li><p>&#x901A;&#x8FC7;Application.yml&#x914D;&#x7F6E;</p>
<pre><code class="lang-yml"><span class="hljs-attr">server:</span>
<span class="hljs-attr">  port:</span> <span class="hljs-number">9527</span>

<span class="hljs-attr">spring:</span>
<span class="hljs-attr">  application:</span>
<span class="hljs-attr">    name:</span> cloud-gateway
  <span class="hljs-comment"># &#x914D;&#x7F6E;gateway</span>
<span class="hljs-attr">  cloud:</span>
<span class="hljs-attr">    gateway:</span>
<span class="hljs-attr">      routes:</span>
<span class="hljs-attr">        - id:</span> payment_route                      <span class="hljs-comment"># &#x8DEF;&#x7531;&#x7684;id ,&#x6CA1;&#x6709;&#x56FA;&#x5B9A;&#x89C4;&#x5219;&#x4F46;&#x662F;&#x8981;&#x6C42;&#x552F;&#x4E00;&#xFF0C;&#x5EFA;&#x8BAE;&#x914D;&#x5408;&#x670D;&#x52A1;&#x540D;</span>
          <span class="hljs-comment">#uri: http://localhost:8001            # &#x5339;&#x914D;&#x540E;&#x63D0;&#x4F9B;&#x670D;&#x52A1;&#x7684;&#x8DEF;&#x7531;&#x5730;&#x5740;&#xFF08;&#x5199;&#x6B7B;&#x4E86;&#x5730;&#x5740;&#xFF0C;&#x4E0D;&#x597D;&#x7684;&#x5199;&#x6CD5;&#xFF09;</span>
<span class="hljs-attr">          uri:</span> lb://eureka-provider-payment      <span class="hljs-comment"># &#x901A;&#x8FC7;&#x670D;&#x52A1;&#x540D;&#x5339;&#x914D; &#xFF08;&#x5E38;&#x7528;&#x7684;&#x5199;&#x6CD5;&#xFF09;</span>
<span class="hljs-attr">          predicates:</span>
<span class="hljs-bullet">            -</span> Path=/payment/getPaymentById/**    <span class="hljs-comment"># &#x65AD;&#x8A00;&#xFF0C;&#x8DEF;&#x5F84;&#x5339;&#x914D;&#x7684;&#x8FDB;&#x884C;&#x8DEF;&#x7531;</span>
<span class="hljs-attr">      discovery:</span>
<span class="hljs-attr">        locator:</span>
<span class="hljs-attr">          enabled:</span> <span class="hljs-literal">true</span>                          <span class="hljs-comment">#&#x5F00;&#x542F;&#x4ECE;&#x6CE8;&#x518C;&#x4E2D;&#x5FC3;&#x52A8;&#x6001;&#x521B;&#x5EFA;&#x8DEF;&#x7531;&#x7684;&#x529F;&#x80FD;&#xFF0C;&#x5229;&#x7528;&#x5FAE;&#x670D;&#x52A1;&#x540D;&#x79F0;&#x8FDB;&#x884C;&#x8DEF;&#x7531;</span>

<span class="hljs-attr">eureka:</span>
<span class="hljs-attr">  instance:</span>
<span class="hljs-attr">    hostname:</span> cloud-gateway-service
<span class="hljs-attr">  client:</span>
<span class="hljs-attr">    register-with-eureka:</span> <span class="hljs-literal">true</span>
<span class="hljs-attr">    fetch-registry:</span> <span class="hljs-literal">true</span>
<span class="hljs-attr">    service-url:</span>
<span class="hljs-attr">      defaultZone:</span> http://localhost:<span class="hljs-number">7001</span>/eureka/
</code></pre>
</li>
</ul>
<ul>
<li><p>&#x901A;&#x8FC7;&#x81EA;&#x5B9A;&#x4E49;bean&#x914D;&#x7F6E;</p>
<pre><code class="lang-java"><span class="hljs-meta">@Configuration</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">GateWayConfig</span> </span>{
    <span class="hljs-meta">@Bean</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> RouteLocator <span class="hljs-title">customRouteLocator</span><span class="hljs-params">(RouteLocatorBuilder builder)</span></span>{
        RouteLocatorBuilder.Builder routes = builder.routes();
        routes.route(<span class="hljs-string">&quot;news-baidu&quot;</span>,r-&gt; r.path(<span class="hljs-string">&quot;/guonei&quot;</span>).uri(<span class="hljs-string">&quot;https://news.baidu.com/guonei&quot;</span>)).build();
        <span class="hljs-keyword">return</span> routes.build();
    }
}
</code></pre>
</li>
</ul>
<h3 id="4&#x8DEF;&#x7531;&#x5339;&#x914D;&#x89C4;&#x5219;&#xFF08;&#x65AD;&#x8A00;&#xFF09;"><a name="4&#x8DEF;&#x7531;&#x5339;&#x914D;&#x89C4;&#x5219;&#xFF08;&#x65AD;&#x8A00;&#xFF09;" class="plugin-anchor" href="#4&#x8DEF;&#x7531;&#x5339;&#x914D;&#x89C4;&#x5219;&#xFF08;&#x65AD;&#x8A00;&#xFF09;"><i class="fa fa-link" aria-hidden="true"></i></a>4.&#x8DEF;&#x7531;&#x5339;&#x914D;&#x89C4;&#x5219;&#xFF08;&#x65AD;&#x8A00;&#xFF09;</h3>
<p>Spring Cloud Gateway &#x7684;&#x529F;&#x80FD;&#x5F88;&#x5F3A;&#x5927;&#xFF0C;&#x6211;&#x4EEC;&#x4EC5;&#x4EC5;&#x901A;&#x8FC7; Predicates &#x7684;&#x8BBE;&#x8BA1;&#x5C31;&#x53EF;&#x4EE5;&#x770B;&#x51FA;&#x6765;&#xFF0C;&#x524D;&#x9762;&#x6211;&#x4EEC;&#x53EA;&#x662F;&#x4F7F;&#x7528;&#x4E86; predicates &#x8FDB;&#x884C;&#x4E86;&#x7B80;&#x5355;&#x7684;path &#x5339;&#x914D;&#xFF0C;&#x5176;&#x5B9E; Spring Cloud Gataway &#x5E2E;&#x6211;&#x4EEC;&#x5185;&#x7F6E;&#x4E86;&#x5F88;&#x591A; Predicates &#x529F;&#x80FD;&#x3002;</p>
<p>Spring Cloud Gateway &#x662F;&#x901A;&#x8FC7; Spring WebFlux &#x7684; HandlerMapping &#x505A;&#x4E3A;&#x5E95;&#x5C42;&#x652F;&#x6301;&#x6765;&#x5339;&#x914D;&#x5230;&#x8F6C;&#x53D1;&#x8DEF;&#x7531;&#xFF0C;<strong>Spring Cloud Gateway &#x5185;&#x7F6E;&#x4E86;&#x5F88;&#x591A; Predicates &#x5DE5;&#x5382;&#xFF0C;&#x8FD9;&#x4E9B; Predicates &#x5DE5;&#x5382;&#x901A;&#x8FC7;&#x4E0D;&#x540C;&#x7684; HTTP &#x8BF7;&#x6C42;&#x53C2;&#x6570;&#x6765;&#x5339;&#x914D;&#xFF0C;&#x591A;&#x4E2A; Predicates &#x5DE5;&#x5382;&#x53EF;&#x4EE5;&#x7EC4;&#x5408;&#x4F7F;&#x7528;</strong>&#x3002;</p>
<p>&#x901A;&#x8FC7;&#x542F;&#x52A8;&#x65E5;&#x5FD7;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x627E;&#x5230;&#x5982;&#x4E0B;&#x90E8;&#x5206;&#xFF1A;</p>
<p><img src="https://tva1.sinaimg.cn/large/e6c9d24ely1h3w43b84wdj21ca0g045x.jpg" alt="&#x5DE5;&#x5382;"></p>
<p>&#x5E38;&#x89C1;&#x7684;&#x65AD;&#x8A00;&#x5982;&#x4E0B;&#x8868;&#xFF08;&#x90E8;&#x5206;&#xFF09;&#xFF1A;</p>
<table>
<thead>
<tr>
<th>&#x65AD;&#x8A00;</th>
<th>&#x793A;&#x4F8B;</th>
<th>&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td>Path</td>
<td>- Path=/dept/list/**</td>
<td>&#x5F53;&#x8BF7;&#x6C42;&#x8DEF;&#x5F84;&#x4E0E; /dept/list/** &#x5339;&#x914D;&#x65F6;&#xFF0C;&#x8BE5;&#x8BF7;&#x6C42;&#x624D;&#x80FD;&#x88AB;&#x8F6C;&#x53D1;&#x5230; <a href="http://localhost:8001" target="_blank">http://localhost:8001</a> &#x4E0A;&#x3002;</td>
</tr>
<tr>
<td>Before</td>
<td>- Before=2021-10-20T11:47:34.255+08:00[Asia/Shanghai]</td>
<td>&#x5728; 2021 &#x5E74; 10 &#x6708; 20 &#x65E5; 11 &#x65F6; 47 &#x5206; 34.255 &#x79D2;&#x4E4B;&#x524D;&#x7684;&#x8BF7;&#x6C42;&#xFF0C;&#x624D;&#x4F1A;&#x88AB;&#x8F6C;&#x53D1;&#x5230; <a href="http://localhost:8001" target="_blank">http://localhost:8001</a> &#x4E0A;&#x3002;</td>
</tr>
<tr>
<td>After</td>
<td>- After=2021-10-20T11:47:34.255+08:00[Asia/Shanghai]</td>
<td>&#x5728; 2021 &#x5E74; 10 &#x6708; 20 &#x65E5; 11 &#x65F6; 47 &#x5206; 34.255 &#x79D2;&#x4E4B;&#x540E;&#x7684;&#x8BF7;&#x6C42;&#xFF0C;&#x624D;&#x4F1A;&#x88AB;&#x8F6C;&#x53D1;&#x5230; <a href="http://localhost:8001" target="_blank">http://localhost:8001</a> &#x4E0A;</td>
</tr>
<tr>
<td>Between</td>
<td>- Between=2021-10-20T15:18:33.226+08:00[Asia/Shanghai],2021-10-20T15:23:33.226+08:00[Asia/Shanghai]</td>
<td>&#x5728; 2021 &#x5E74; 10 &#x6708; 20 &#x65E5; 15 &#x65F6; 18 &#x5206; 33.226 &#x79D2; &#x5230; 2021 &#x5E74; 10 &#x6708; 20 &#x65E5; 15 &#x65F6; 23 &#x5206; 33.226 &#x79D2;&#x4E4B;&#x95F4;&#x7684;&#x8BF7;&#x6C42;&#xFF0C;&#x624D;&#x4F1A;&#x88AB;&#x8F6C;&#x53D1;&#x5230; <a href="http://localhost:8001" target="_blank">http://localhost:8001</a> &#x670D;&#x52A1;&#x5668;&#x4E0A;</td>
</tr>
<tr>
<td>Cookie</td>
<td>- Cookie=name,c.biancheng.net</td>
<td>&#x643A;&#x5E26; Cookie &#x4E14; Cookie &#x7684;&#x5185;&#x5BB9;&#x4E3A; name=c.biancheng.net &#x7684;&#x8BF7;&#x6C42;&#xFF0C;&#x624D;&#x4F1A;&#x88AB;&#x8F6C;&#x53D1;&#x5230; <a href="http://localhost:8001" target="_blank">http://localhost:8001</a> &#x4E0A;&#xFF08;&#x6B63;&#x5219;&#xFF09;</td>
</tr>
<tr>
<td>Header</td>
<td>- Header=X-Request-Id,\d+</td>
<td>&#x8BF7;&#x6C42;&#x5934;&#x4E0A;&#x643A;&#x5E26;&#x5C5E;&#x6027; X-Request-Id &#x4E14;&#x5C5E;&#x6027;&#x503C;&#x4E3A;&#x6574;&#x6570;&#x7684;&#x8BF7;&#x6C42;&#xFF0C;&#x624D;&#x4F1A;&#x88AB;&#x8F6C;&#x53D1;&#x5230; <a href="http://localhost:8001" target="_blank">http://localhost:8001</a> &#x4E0A;&#xFF08;&#x6B63;&#x5219;&#xFF09;</td>
</tr>
<tr>
<td>Method</td>
<td>- Method=GET</td>
<td>&#x53EA;&#x6709; GET &#x8BF7;&#x6C42;&#x624D;&#x4F1A;&#x88AB;&#x8F6C;&#x53D1;&#x5230; <a href="http://localhost:8001" target="_blank">http://localhost:8001</a> &#x4E0A;</td>
</tr>
<tr>
<td>Host</td>
<td>- Host=www.liang.com</td>
<td>&#x53EA;&#x6709;&#x57DF;&#x540D;&#x4E3A;www.liang.com&#x7684;&#x8BF7;&#x6C42;&#x624D;&#x4F1A;&#x8F6C;&#x53D1;&#x5230;<a href="http://localhost:8001&#x4E0A;" target="_blank">http://localhost:8001&#x4E0A;</a></td>
</tr>
</tbody>
</table>
<h3 id="5&#x8FC7;&#x6EE4;&#x5668;&#x89C4;&#x5219;"><a name="5&#x8FC7;&#x6EE4;&#x5668;&#x89C4;&#x5219;" class="plugin-anchor" href="#5&#x8FC7;&#x6EE4;&#x5668;&#x89C4;&#x5219;"><i class="fa fa-link" aria-hidden="true"></i></a>5.&#x8FC7;&#x6EE4;&#x5668;&#x89C4;&#x5219;</h3>
<p>&#x901A;&#x5E38;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x51FA;&#x4E8E;&#x5B89;&#x5168;&#x65B9;&#x9762;&#x7684;&#x8003;&#x8651;&#xFF0C;&#x670D;&#x52A1;&#x7AEF;&#x63D0;&#x4F9B;&#x7684;&#x670D;&#x52A1;&#x5F80;&#x5F80;&#x90FD;&#x4F1A;&#x6709;&#x4E00;&#x5B9A;&#x7684;&#x6821;&#x9A8C;&#x903B;&#x8F91;&#xFF0C;&#x4F8B;&#x5982;&#x7528;&#x6237;&#x767B;&#x9646;&#x72B6;&#x6001;&#x6821;&#x9A8C;&#x3001;&#x7B7E;&#x540D;&#x6821;&#x9A8C;&#x7B49;&#x3002;</p>
<p>&#x5728;&#x5FAE;&#x670D;&#x52A1;&#x67B6;&#x6784;&#x4E2D;&#xFF0C;&#x7CFB;&#x7EDF;&#x7531;&#x591A;&#x4E2A;&#x5FAE;&#x670D;&#x52A1;&#x7EC4;&#x6210;&#xFF0C;&#x6240;&#x6709;&#x8FD9;&#x4E9B;&#x670D;&#x52A1;&#x90FD;&#x9700;&#x8981;&#x8FD9;&#x4E9B;&#x6821;&#x9A8C;&#x903B;&#x8F91;&#xFF0C;&#x6B64;&#x65F6;&#x6211;&#x4EEC;&#x5C31;&#x53EF;&#x4EE5;&#x5C06;&#x8FD9;&#x4E9B;&#x6821;&#x9A8C;&#x903B;&#x8F91;&#x5199;&#x5230; Spring Cloud Gateway &#x7684; Filter &#x8FC7;&#x6EE4;&#x5668;&#x4E2D;&#x3002;</p>
<p><strong>&#x4ECE;&#x8FC7;&#x6EE4;&#x5668;&#x7684;&#x7C7B;&#x578B;&#x5206;&#x7C7B;&#xFF1A;</strong></p>
<table>
<thead>
<tr>
<th>&#x7C7B;&#x578B;</th>
<th>&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td>Pre &#x7C7B;&#x578B;</td>
<td>&#x8FD9;&#x79CD;&#x8FC7;&#x6EE4;&#x5668;&#x5728;&#x8BF7;&#x6C42;&#x88AB;&#x8F6C;&#x53D1;&#x5230;&#x5FAE;&#x670D;&#x52A1;&#x4E4B;&#x524D;&#x53EF;&#x4EE5;&#x5BF9;&#x8BF7;&#x6C42;&#x8FDB;&#x884C;&#x62E6;&#x622A;&#x548C;&#x4FEE;&#x6539;&#xFF0C;&#x4F8B;&#x5982;&#x53C2;&#x6570;&#x6821;&#x9A8C;&#x3001;&#x6743;&#x9650;&#x6821;&#x9A8C;&#x3001;&#x6D41;&#x91CF;&#x76D1;&#x63A7;&#x3001;&#x65E5;&#x5FD7;&#x8F93;&#x51FA;&#x4EE5;&#x53CA;&#x534F;&#x8BAE;&#x8F6C;&#x6362;&#x7B49;&#x64CD;&#x4F5C;&#x3002;</td>
</tr>
<tr>
<td>Post &#x7C7B;&#x578B;</td>
<td>&#x8FD9;&#x79CD;&#x8FC7;&#x6EE4;&#x5668;&#x5728;&#x5FAE;&#x670D;&#x52A1;&#x5BF9;&#x8BF7;&#x6C42;&#x505A;&#x51FA;&#x54CD;&#x5E94;&#x540E;&#x53EF;&#x4EE5;&#x5BF9;&#x54CD;&#x5E94;&#x8FDB;&#x884C;&#x62E6;&#x622A;&#x548C;&#x518D;&#x5904;&#x7406;&#xFF0C;&#x4F8B;&#x5982;&#x4FEE;&#x6539;&#x54CD;&#x5E94;&#x5185;&#x5BB9;&#x6216;&#x54CD;&#x5E94;&#x5934;&#x3001;&#x65E5;&#x5FD7;&#x8F93;&#x51FA;&#x3001;&#x6D41;&#x91CF;&#x76D1;&#x63A7;&#x7B49;&#x3002;</td>
</tr>
</tbody>
</table>
<p><strong>&#x4ECE;&#x8FC7;&#x6EE4;&#x5668;&#x7684;&#x4F5C;&#x7528;&#x8303;&#x56F4;&#x5206;&#x7C7B;&#xFF1A;</strong></p>
<table>
<thead>
<tr>
<th>&#x7C7B;&#x578B;</th>
<th>&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td>GatewayFilter</td>
<td>&#x5E94;&#x7528;&#x5728;&#x5355;&#x4E2A;&#x8DEF;&#x7531;&#x6216;&#x8005;&#x4E00;&#x7EC4;&#x8DEF;&#x7531;&#x4E0A;&#x7684;&#x8FC7;&#x6EE4;&#x5668;&#x3002;</td>
</tr>
<tr>
<td>GlobalFilter</td>
<td>&#x5E94;&#x7528;&#x5728;&#x6240;&#x6709;&#x7684;&#x8DEF;&#x7531;&#x4E0A;&#x7684;&#x8FC7;&#x6EE4;&#x5668;&#x3002;</td>
</tr>
</tbody>
</table>
<p>&#x5B98;&#x65B9;&#x5185;&#x7F6E;&#x4E86;31&#x79CD;GatewayFilter&#x5355;&#x4E2A;&#x8FC7;&#x6EE4;&#x5668;&#xFF0C;&#x4E0D;&#x518D;&#x4E00;&#x4E00;&#x5217;&#x4E3E;&#xFF0C;&#x7528;&#x6CD5;&#x548C;&#x65AD;&#x8A00;&#x914D;&#x7F6E;&#x4E00;&#x6837;</p>
<pre><code class="lang-yml"><span class="hljs-attr">- id:</span> provider_dept_get_routh
<span class="hljs-attr">  uri:</span> lb://MICROSERVICECLOUDPROVIDERDEPT <span class="hljs-comment">#&#x4F7F;&#x7528;&#x670D;&#x52A1;&#x540D;&#x4EE3;&#x66FF;&#x4E0A;&#x9762;&#x7684;&#x5177;&#x4F53;&#x5E26;&#x7AEF;&#x53E3;</span>
<span class="hljs-attr">  predicates:</span>
<span class="hljs-bullet">    -</span> Path=/get/**
<span class="hljs-attr">  filters:</span>
<span class="hljs-bullet">    -</span> PrefixPath=/dept <span class="hljs-comment">#&#x5728;&#x8BF7;&#x6C42;&#x8DEF;&#x5F84;&#x4E0A;&#x589E;&#x52A0;&#x4E00;&#x4E2A;&#x524D;&#x7F00; /dept</span>
</code></pre>
<p>&#x5B98;&#x65B9;&#x8FD8;&#x5185;&#x7F6E;10&#x591A;&#x79CD;GlobalFilter &#x5168;&#x5C40;&#x8FC7;&#x6EE4;&#x5668;&#xFF0C;&#x4F8B;&#x5982;&#x4E0E;&#x8F6C;&#x53D1;&#x3001;&#x8DEF;&#x7531;&#x3001;&#x8D1F;&#x8F7D;&#x5747;&#x8861;&#x7B49;&#x76F8;&#x5173;&#x7684;&#x5168;&#x5C40;&#x8FC7;&#x6EE4;&#x5668;&#x3002;&#x4F46;&#x5728;&#x5B9E;&#x9645;&#x7684;&#x9879;&#x76EE;&#x5F00;&#x53D1;&#x4E2D;&#xFF0C;&#x901A;&#x5E38;&#x6211;&#x4EEC;&#x90FD;&#x4F1A;&#x81EA;&#x5B9A;&#x4E49;&#x4E00;&#x4E9B;&#x81EA;&#x5DF1;&#x7684; GlobalFilter &#x5168;&#x5C40;&#x8FC7;&#x6EE4;&#x5668;&#x4EE5;&#x6EE1;&#x8DB3;&#x6211;&#x4EEC;&#x81EA;&#x8EAB;&#x7684;&#x4E1A;&#x52A1;&#x9700;&#x6C42;&#xFF0C;&#x800C;&#x5F88;&#x5C11;&#x76F4;&#x63A5;&#x4F7F;&#x7528; Spring Cloud Config &#x63D0;&#x4F9B;&#x8FD9;&#x4E9B;&#x9ED8;&#x8BA4;&#x7684; GlobalFilter&#x3002;</p>
<p><strong>&#x81EA;&#x5B9A;&#x4E49;&#x5168;&#x5C40;&#x8FC7;&#x6EE4;&#x5668;</strong></p>
<pre><code class="lang-java"><span class="hljs-meta">@Component</span>
<span class="hljs-meta">@Slf</span>4j
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyGlobalFilter</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">GlobalFilter</span>, <span class="hljs-title">Ordered</span> </span>{

    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> Mono&lt;Void&gt; <span class="hljs-title">filter</span><span class="hljs-params">(ServerWebExchange exchange, GatewayFilterChain chain)</span> </span>{
        log.info(<span class="hljs-string">&quot;&#x8FDB;&#x5165;&#x81EA;&#x5B9A;&#x4E49;&#x7684;&#x5168;&#x5C40;&#x8FC7;&#x6EE4;&#x5668; MyGlobalFilter&quot;</span> + <span class="hljs-keyword">new</span> Date());
        String uname = exchange.getRequest().getQueryParams().getFirst(<span class="hljs-string">&quot;uname&quot;</span>);
        <span class="hljs-keyword">if</span> (uname == <span class="hljs-keyword">null</span>) {
            log.info(<span class="hljs-string">&quot;&#x53C2;&#x6570; uname &#x4E0D;&#x80FD;&#x4E3A; null&#xFF01;&quot;</span>);
            exchange.getResponse().setStatusCode(HttpStatus.NOT_ACCEPTABLE);
            <span class="hljs-keyword">return</span> exchange.getResponse().setComplete();<span class="hljs-comment">//&#x8BBE;&#x7F6E;&#x62D2;&#x7EDD;</span>
        }
        <span class="hljs-keyword">return</span> chain.filter(exchange);<span class="hljs-comment">//&#x8FDB;&#x884C;&#x8FC7;&#x6EE4;&#x5668;&#x94FE;&#x4E0A;&#x7684;&#x4E0B;&#x4E00;&#x4E2A;&#x8FC7;&#x6EE4;</span>
    }

    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> <span class="hljs-title">getOrder</span><span class="hljs-params">()</span> </span>{
        <span class="hljs-comment">//&#x8FC7;&#x6EE4;&#x5668;&#x7684;&#x987A;&#x5E8F;&#xFF0C;0 &#x8868;&#x793A;&#x7B2C;&#x4E00;&#x4E2A;</span>
        <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;
    }
}
</code></pre>
<h3 id="6&#x63A5;&#x5165;&#x4EE3;&#x7801;"><a name="6&#x63A5;&#x5165;&#x4EE3;&#x7801;" class="plugin-anchor" href="#6&#x63A5;&#x5165;&#x4EE3;&#x7801;"><i class="fa fa-link" aria-hidden="true"></i></a>6.&#x63A5;&#x5165;&#x4EE3;&#x7801;</h3>
<p>pom.xml(&#x6CE8;&#x610F;&#x4E0D;&#x80FD;&#x5F15;&#x5165;web&#x6A21;&#x5757;&#xFF0C;&#x542F;&#x52A8;&#x4F1A;&#x62A5;&#x9519;)</p>
<pre><code class="lang-xml"><span class="php"><span class="hljs-meta">&lt;?</span>xml version=<span class="hljs-string">&quot;1.0&quot;</span> encoding=<span class="hljs-string">&quot;UTF-8&quot;</span><span class="hljs-meta">?&gt;</span></span>
<span class="hljs-tag">&lt;<span class="hljs-name">project</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">&quot;http://maven.apache.org/POM/4.0.0&quot;</span>
         <span class="hljs-attr">xmlns:xsi</span>=<span class="hljs-string">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span>
         <span class="hljs-attr">xsi:schemaLocation</span>=<span class="hljs-string">&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">parent</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>bigdata<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>com.****.springcloud<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>1.0-SNAPSHOT<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">parent</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">modelVersion</span>&gt;</span>4.0.0<span class="hljs-tag">&lt;/<span class="hljs-name">modelVersion</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>cloud-gateway<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>


    <span class="hljs-tag">&lt;<span class="hljs-name">dependencies</span>&gt;</span>

        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.cloud<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-cloud-starter-gateway<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

        <span class="hljs-comment">&lt;!--eureka--&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.cloud<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-cloud-starter-netflix-eureka-client<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>


        <span class="hljs-comment">&lt;!--&#x70ED;&#x90E8;&#x7F72;--&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-boot-devtools<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">scope</span>&gt;</span>runtime<span class="hljs-tag">&lt;/<span class="hljs-name">scope</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">optional</span>&gt;</span>true<span class="hljs-tag">&lt;/<span class="hljs-name">optional</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
        <span class="hljs-comment">&lt;!--lombok--&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.projectlombok<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>lombok<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">optional</span>&gt;</span>true<span class="hljs-tag">&lt;/<span class="hljs-name">optional</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
        <span class="hljs-comment">&lt;!--test--&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-boot-starter-test<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">scope</span>&gt;</span>test<span class="hljs-tag">&lt;/<span class="hljs-name">scope</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>com.*****.springcloud<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>api-common<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>${project.version}<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

    <span class="hljs-tag">&lt;/<span class="hljs-name">dependencies</span>&gt;</span>

<span class="hljs-tag">&lt;/<span class="hljs-name">project</span>&gt;</span>
</code></pre>
<p>&#x542F;&#x52A8;&#x7C7B; CloudGatewayApplication</p>
<pre><code class="lang-java"><span class="hljs-meta">@SpringBootApplication</span>
<span class="hljs-meta">@EnableEurekaClient</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">CloudGatewayApplication</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{
        SpringApplication.run(CloudGatewayApplication.class,args);
    }
}
</code></pre>
<p>application.yml &#x914D;&#x7F6E;&#x6587;&#x4EF6;  &#xFF0C;&#x7701;&#x7565;&#xFF0C;&#x540C;&#x4E0A;&#x6587;&#x3002;</p>
<p>bean&#x65B9;&#x5F0F;&#x914D;&#x7F6E;&#x8DEF;&#x7531;&#xFF0C;&#x7701;&#x7565;&#xFF0C;&#x540C;&#x4E0A;&#x6587;&#x3002;</p>
<p>&#x81EA;&#x5B9A;&#x4E49;&#x5168;&#x5C40;&#x8FC7;&#x6EE4;&#x5668;&#xFF0C;&#x7701;&#x7565;&#xFF0C;&#x540C;&#x4E0A;&#x6587;&#x3002;</p>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; mine 2022-2025 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x6587;&#x4EF6;&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;&#xFF1A;
2022-07-05 16:40:27
</span></footer>
<script>console.log("plugin-popup....");document.onclick = function(e){ e.target.tagName === "IMG" && window.open(e.target.src,e.target.src)}</script><style>img{cursor:pointer}</style>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="11.熔断器-Hystrix.html" class="navigation navigation-prev " aria-label="Previous page: 熔断器-Hystrix">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="13.配置中心-Config.html" class="navigation navigation-next " aria-label="Next page: 配置中心-Config">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"网关-Gateway","level":"4.1.11","depth":2,"next":{"title":"配置中心-Config","level":"4.1.12","depth":2,"path":"springcloud/13.配置中心-Config.md","ref":"springcloud/13.配置中心-Config.md","articles":[]},"previous":{"title":"熔断器-Hystrix","level":"4.1.10","depth":2,"path":"springcloud/11.熔断器-Hystrix.md","ref":"springcloud/11.熔断器-Hystrix.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["back-to-top-button","code","splitter","expandable-chapters-small","anchors","theme-comscore","tbfed-pagefooter","sidebar-style","pageview-count","popup"],"pluginsConfig":{"sidebar-style":{"author":"梁兴龙","title":"《Java 笔记本》"},"tbfed-pagefooter":{"copyright":"Copyright &copy mine 2022-2025","modify_label":"文件修订时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"splitter":{},"search":{},"popup":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"code":{"copyButtons":false},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"theme-comscore":{},"back-to-top-button":{},"pageview-count":{},"expandable-chapters-small":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"anchors":{}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"springcloud/12.网关-Gateway.md","mtime":"2022-07-05T08:40:27.098Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2022-08-22T03:22:22.085Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sidebar-style/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-pageview-count/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    </body>
</html>

